package org.gcb.core.ui.model;

import javax.swing.AbstractListModel;
import javax.swing.JLabel;
import org.gcb.core.model.EArmorSlot;
import org.gcb.core.model.Toon;
import org.openide.util.ImageUtilities;

/**
 *
 * @author Jason
 */
public class ArmorSlotListModel extends AbstractListModel {

    private final JLabel emptySlot;
    private final Toon toon;
    private final EArmorSlot armorSlot;

    public ArmorSlotListModel(Toon toon, EArmorSlot armorSlot) {
	this.toon = toon;
	this.armorSlot = armorSlot;
	switch (armorSlot) {
	    case ARMOR:
	    default:
		emptySlot = new JLabel(ImageUtilities.loadImageIcon("org/gcb/core/ui/Head.gif", false));
	}
    }

    @Override
    public int getSize() {
	return 1;
    }

    @Override
    public Object getElementAt(int index) {
	if (toon.getEquipment().getWorn().isEmpty(armorSlot) || toon.getEquipment().getWorn().get(armorSlot).getIcon()==null) {
	    emptySlot.setIcon(null);
	    return emptySlot;
	} else {
	    emptySlot.setIcon(toon.getEquipment().getWorn().get(armorSlot).getIcon());
	}
	return emptySlot;
    }
}
